package net.wanho.hospital.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.hospital.po.Orders;
import net.wanho.hospital.po.Patient;
import net.wanho.hospital.service.OrdersService;
import net.wanho.hospital.service.PatientUserService;
import net.wanho.hospital.vo.AdminVo;
import net.wanho.hospital.vo.AjaxResult;
import net.wanho.hospital.vo.PatientVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-27
 */
@Api(tags = "接口")
@RestController
@RequestMapping("/patient")
@RequiredArgsConstructor
public class PatientUserController {

    private final PatientUserService patientUserService;
    private final OrdersService ordersService;

    @ApiOperation("分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public AjaxResult findPage(@ApiParam("当前页") @PathVariable int pageNum,@ApiParam("页大小") @PathVariable int pageSize, Patient patient){
        IPage page = patientUserService.findPage(pageNum,pageSize, patient);
        return AjaxResult.success(page);
    }

    @ApiOperation("按主键查询")
    @GetMapping("/{pId}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable pId){
        return AjaxResult.success(patientUserService.getById(pId));
    }

    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@RequestBody Patient stu){
        patientUserService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody Patient patient){
        patientUserService.updateById(patient);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除")
    @DeleteMapping("/{pId}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable pId){
        patientUserService.removeById(pId);
        return AjaxResult.success();
    }

    @PostMapping("/login")
    public AjaxResult login(int pId, String pPassword){
        PatientVo patientVo = patientUserService.login(pId, pPassword);
        return AjaxResult.success(patientVo);
    }

    @ApiOperation("新增")
    @GetMapping("/addOrder")
    public AjaxResult add(Orders order, String arId){
        ordersService.addOrder(order, arId);
        return AjaxResult.success();
    }

    @GetMapping("/findOrderByPid")
    public AjaxResult findOrderByPid(Integer pId){
        List<Orders> list = ordersService.findByPid(pId);
        return AjaxResult.success(list);
    }
}
